package types;

import org.apache.log4j.Logger;
import config.DatabaseConnection;

public class TextMessage implements DBTableTypes
{
    // Class variables
    private String fromPhone;
    private String messageContents;
    
    // Logger
    @SuppressWarnings("unused")
    private static Logger myLogger = Logger.getLogger(TextMessage.class.getName()); 
    
    /**
     * Constructor
     * @param fromPhone
     * @param messageContents
     */
    public TextMessage(String fromPhone, String messageContents)
    {
	super();
	this.fromPhone = fromPhone;
	this.messageContents = messageContents.trim().toLowerCase();
    }
    
    /**
     * Adds the text message to the database
     * @return success
     */
    @Override
    public boolean keep()
    {
	String query = "" 
		    + "INSERT INTO messages " + "(Message, Phone) " 
		    + "VALUES ('" + messageContents + "', '"  + fromPhone + "')";
	String tableName="Messages";
	return DatabaseConnection.executeQuery(query, tableName);
    }
    
    
    
    // Getters and Setters
    public String getFromPhone()
    {
        return fromPhone;
    }
    public void setFromPhone(String fromPhone)
    {
        this.fromPhone = fromPhone;
    }
    public String getMessageContents()
    {
        return messageContents;
    }
    public void setMessageContents(String messageContents)
    {
        this.messageContents = messageContents;
    }


    // Overloaded methods
    @Override
    public String toString()
    {
	return "TextMessage [fromPhone=" + fromPhone + ", messageContents=" + messageContents + "]";
    }
}
